package com.zut.movie.service.impl;

import com.zut.movie.entity.Movie;
import com.zut.movie.entity.vo.MovieVo;
import com.zut.movie.mapper.CinemaMapper;
import com.zut.movie.mapper.MovieMapper;
import com.zut.movie.service.MovieService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class MovieServiceImpl implements MovieService {

    @Autowired
    public MovieMapper movieMapper;

    @Autowired
    public CinemaMapper cinemaMapper;

    @Override
    @Transactional
    public void insertMovie(Movie movie) {
        movieMapper.insert(movie);
        cinemaMapper.insert(movie.getCinemaData());
    }

    @Override
    public List<MovieVo> getAll() {
        List<MovieVo> list= movieMapper.getAll();
        return list;
    }

    @Override
    @Transactional
    public void del(Long orderId) {
        Long cinemaId= movieMapper.getCinemaIdByOrderId(orderId);
        movieMapper.del(orderId);
        cinemaMapper.del(cinemaId);
    }
}
